using UnityEngine;

public class Ability : MonoBehaviour {

    [SerializeField]
    string _form = "";

    [SerializeField]
    LayerMask _raycastMask = -1;

    [SerializeField]
    float _raycastDistance = 1;

    #region Properties
    public string Form {
        get { return _form; }
        set { _form = value; }
    }

    public float RaycastDistance {
        get { return _raycastDistance; }
        set { _raycastDistance = value; }
    }

    public LayerMask RaycastMask {
        get { return _raycastMask; }
        set { _raycastMask = value; }
    }
    #endregion

    public void Attack(GameObject gameObject) {
        ObstacleController obstacle = gameObject.GetComponent<ObstacleController>();

        if(obstacle) obstacle.Destroy(Form);
    }

    [ContextMenu("Raycast Attack")]
    public void RaycastAttack() {
        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, RaycastDistance, RaycastMask);

        if(hit.collider)
            Attack(hit.rigidbody ? hit.rigidbody.gameObject : hit.collider.gameObject);
    }
}